package com.meitianhui.convenitenbuy.module.store.presenter;

import com.google.gson.Gson;
import com.meitianhui.convenitenbuy.App;
import com.meitianhui.convenitenbuy.base.BaseResponse;
import com.meitianhui.convenitenbuy.config.InfoProvider;
import com.meitianhui.convenitenbuy.http.ResponseObserver;
import com.meitianhui.convenitenbuy.module.order.model.bean.FightGroupShop;
import com.meitianhui.convenitenbuy.module.store.contract.GroupShopCarContract;
import com.meitianhui.convenitenbuy.module.store.http.StoreApiDataSource;
import com.meitianhui.convenitenbuy.module.store.ui.activity.GroupShopCarActivity;

import java.util.HashMap;
import java.util.Map;

public class GroupShopCarPresenter implements GroupShopCarContract.Presenter {

    private GroupShopCarActivity mContext;
    private GroupShopCarContract.View mView;

    public GroupShopCarPresenter(GroupShopCarContract.View view,
                                 GroupShopCarActivity context) {
        this.mView = view;
        this.mContext = context;
    }

    @Override
    public void getGroupSaleDetail(String invitationCode) {
        Map<String, String> map = new HashMap<>();
        map.put("invitation_code", invitationCode);
        String params = new Gson().toJson(map);

        StoreApiDataSource.getInstance()
                .getGroupSaleDetail(InfoProvider.getUserToken(App.getInstance()).getUser_token(),
                        "order.psGroupGoodsDetailFind", params)
                .subscribe(new ResponseObserver<BaseResponse<FightGroupShop>>(mContext, true) {
                    @Override
                    public void onSuccess(BaseResponse<FightGroupShop> response) {
                        if (response.data != null) {
                            mView.getGroupSaleDetailSuccess(response.data);
                        }
                    }

                    @Override
                    public void onFail(int code, String msg) {
                        super.onFail(code, msg);
                        mView.onFail(code, msg);
                    }
                });
    }

    @Override
    public void attachView(Object view) {
    }

    @Override
    public void detachView() {
    }

}
